#ifndef AS5047P_CONFIG_H
#define AS5047P_CONFIG_H
#include "spi.h"
#define AS5047P_NOP_REG          (uint16_t)0x0000
#define AS5047P_ERRFL_REG        (uint16_t)0x0001
#define AS5047P_PROG_REG         (uint16_t)0x0003
#define AS5047P_DIAAGC_REG       (uint16_t)0x3FFC
#define AS5047P_MAG_REG          (uint16_t)0x3FFD
#define AS5047P_ANGLEUNC_REG     (uint16_t)0x3FFE
#define AS5047P_ANGLECOM_REG     (uint16_t)0x3FFF   /*use this register to get angle*/

#define AS5047P_RW_MASK          (uint16_t)(1<<14)  /* 1: Read, 0: Write            */
#define AS5047P_EVEN_PARITY_MASK (uint16_t)(1<<15)  /* 1: Even, 0: Odd              */
#define AS5047P_DATA_MASK        ((uint16_t)0x3FFF)

#define pi 3.1415926
#define AS5047P_RAD2VALUE(x)     (x * (1<<14) / (2 * pi))
//
#define AS5047P_WRITE_OK         0
#define AS5047P_RW_TIMEOUT       -1
#define AS5047P_PARITY_ERROR     -2

#define WaitSPI_Free(device)      \
                                _SPI_GetStatusFlag(device, SPI_FLAG_TXE)
typedef struct Push_motor
{
    SPI_Device *device      ;
    uint16_t   current_angle;
    uint16_t   refer_angle  ;
    uint16_t   offset;
}Push_motor;
int16_t AS5047P_WriteREG(SPI_Device device, uint16_t addr, uint16_t data);
int16_t AS5047P_ReadREG(SPI_Device device, uint16_t addr);
int Parity_Bit_Calculate(u16 data);
#endif
